OPERATOR OVERLOADING
_________________________________________________________________________

You can use the 'operator' keyword to overload normal C operators to perform basic functions like adding and subtracting the way you would normally, by using the '+' and '-' symbols.  Thus, instead of creating a function to do something like this:

  Vector = myAddTwoVectors( Vector1, Vector2 );

you would overload the '+' operator so that the above statement would look like this:

  Vector = Vector1 + Vector2;

The mechanics for operator overloading are shown in the following code segment:

 // vector.cp
  #include <iostream.h>
  
  class Vector
  
      float x;
      float y;
    public:
      Vector( int a, int b );
      Vector &operator+( Vector &V );
      void print( void );
  ;
  
  Vector::Vector( int a, int b )
  
    x = a;
    y = b;

  Vector &Vector::operator+( Vector &V )
  
    Vector resultV( 0, 0 );
    
    resultV.x = x + V.x;
    resultV.y = y + V.y;
    
    return resultV;

  void Vector::print( void )
  
    cout << "x: " << x << endl;
    cout << "y: " << y << endl;

  void main( void )
  
    Vector vectorA( 3, 4 );
    Vector vectorB( 2, 7 );
    Vector vectorResult( 0, 0 );
    
    vectorResult = vectorA + vectorB;
    vectorResult.print();
  
  // end vector.cp